<template>
  <div class="home">
    <Swiper :list="LunboList"></Swiper>
    <sortIcon></sortIcon>
    <div class="banner">
      <span>精品优选</span>
      <el-carousel :interval="4000" type="card" height="102px">
        <el-carousel-item v-for="item in goodsBanner" :key="item.id">
          <img :src="item.bannerImg" alt=""/>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="fg">
      <span>新品上线</span>
    </div>
    <Goods :newGoodses="newGoodses"></Goods>
    <div class="fg">
      <span>热门商品</span>
    </div>
    <Goods :newGoodses="recommendGoodses"></Goods>
    <div class="fg">
      <span>最新推荐</span>
    </div>
    <Goods :newGoodses="hotGoodses"></Goods>
  </div>
</template>
<script>
import Swiper from '../../components/Comment/Swiper/index.vue'
import Goods from '../../components/Comment/goods/index.vue'
import sortIcon from '../../components/Comment/sortIcon/sortIcon.vue'
import { getGoods } from '@/api/home'
import { mapState } from 'vuex'

export default {
  components: {
    Swiper,
    Goods,
    sortIcon
  },
  data() {
    return {
      LunboList: []
    }
  },
  methods: {
    async getLunbo() {
      const res = await getGoods()
      this.LunboList = res.data.carousels
    }
  },
  computed: {
    ...mapState('goods', ['hotGoodses']),
    ...mapState('goods', ['newGoodses']),
    ...mapState('goods', ['recommendGoodses']),
    ...mapState('goods', ['goodsBanner'])
  },
  mounted() {
    this.getLunbo()
    this.$store.dispatch('goods/ReqnewGoodses')
    this.$store.dispatch('goods/ReqrecommendGoodses')
    this.$store.dispatch('goods/ReqhotGoodses')
    this.$store.dispatch('goods/ReqgetgoodsBanner')
  }
}
</script>
<style lang="scss">
.el-carousel {
  margin-top: 10px;
  margin-right: 0px;
}

.el-carousel__container {
  margin-right: 39px;
  margin-top: 6px;
}

.el-carousel__item {
  border-radius: 10px;
  width: 56%;

  img {
    width: 100%;
    height: 100%;
  }
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.banner {
  span {
    font-size: 18px;
    font-weight: 700;
    color: rgba(1, 141, 214, 0.9);
    display: block;
    padding-left: 6px;
    margin-bottom: 10px;
    line-height: 50px;
    height: 50px;
    background-color: #f9f9f9;
    text-align: center;
  }

  margin-top: 10px;
}

.fg {
  span {
    font-size: 18px;
    font-weight: 700;
    color: rgba(1, 141, 214, 0.9);
    display: block;
    padding-left: 6px;
    line-height: 50px;
    height: 50px;
    background-color: #f9f9f9;
    text-align: center;
  }
}
</style>
